package br.edu.ifrn.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;

import br.edu.ifrn.exeption.CategoriaUsuarioException;
import br.edu.ifrn.model.CategoriaUsuario;

public class CategoriaUsuarioDAO extends AbstractDAO {
	
	public CategoriaUsuarioDAO(EntityManager em) {
		AbstractDAO.em = em;
	}

	@Override
	public <E> List<E> listar(){
		Query q = em.createQuery("select object(c) from CategoriaUsuario as c");
		return q.getResultList();
	}
	
	public boolean isAssociado(Long id){
		try{
			em.createQuery("Select u From Usuario u where u.categoria.id = " + id).getSingleResult();
			return true;
		}
		catch (NoResultException e) {
			return false;
		}
	}
}
